package miracle.joker.design.command.demo2;

public class DeleteTextCommand implements Command {
    private Document document;
    private String deletedText;

    public DeleteTextCommand(Document document) {
        this.document = document;
    }

    @Override
    public void execute() {
        deletedText = document.getContent().substring(document.getCursor() - 1, document.getCursor());
        document.deleteText();
    }

    @Override
    public void undo() {
        document.appendText(deletedText);
    }

    @Override
    public void redo() {
        document.deleteText();
    }
}
